using UnityEngine;

public class UpgradeUI : MonoBehaviour
{
	private GameObject uiobj;

	public UIEventListener armourbtn;

	public UIEventListener machinebtn;

	public UIEventListener multiplemissilebtn;

	public UIEventListener longmissilebtn;

	public UIEventListener missilelurebtn;

	public UISprite[] btnitemflag;

	public UISprite[] btnsprite;

	public GameObject[] itemobj;

	public WeaponItem[] weaponitem;

	private int CurPlane;

	public UILabel[] weaponname;

	private int curitemnum = -1;

	private void Start()
	{
		armourbtn.onClick = clickarmour;
		machinebtn.onClick = clickmachine;
		multiplemissilebtn.onClick = clickmultiple;
		longmissilebtn.onClick = clicklong;
		missilelurebtn.onClick = clickmissilelure;
	}

	public void init_ui_info(int planeindex)
	{
		for (int i = 0; i < weaponitem.Length; i++)
		{
			weaponitem[i].enable(planeindex);
			if (i + 1 <= MenuDataController.instance.PlaneData[planeindex].weapons)
			{
				btnsprite[i].spriteName = "QH_biaoQianWeiXuanZhong";
				weaponname[i].color = Color.white;
			}
			else
			{
				btnsprite[i].spriteName = "QH_biaoQianWeiXuanZhongHui";
				weaponname[i].color = Color.gray;
			}
		}
		change_item(0);
	}

	public void clickarmour(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		change_item(0);
	}

	public void clickmachine(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		change_item(1);
	}

	public void clickmultiple(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		change_item(2);
	}

	public void clicklong(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		change_item(3);
	}

	public void clickmissilelure(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		change_item(4);
	}

	public void change_item(int itemnum)
	{
		if (curitemnum == itemnum)
		{
			return;
		}
		curitemnum = itemnum;
		for (int i = 0; i < btnitemflag.Length; i++)
		{
			if (i == itemnum)
			{
				btnitemflag[i].enabled = true;
				NGUITools.SetActive(itemobj[i], state: true);
			}
			else
			{
				btnitemflag[i].enabled = false;
				NGUITools.SetActive(itemobj[i], state: false);
			}
		}
		weaponitem[itemnum].resetScroll();
	}

	public void enable(int planeindex)
	{
		if (uiobj == null)
		{
			uiobj = base.gameObject;
		}
		NGUITools.SetActive(uiobj, state: true);
		CurPlane = planeindex;
		init_ui_info(CurPlane);
	}

	public void disable()
	{
		curitemnum = -1;
		NGUITools.SetActive(uiobj, state: false);
	}
}
